package com.xlhj.boot.common;

import lombok.Data;

/**
 * @author: liucaijing
 * @description: ResultData
 * @date: 2021/6/21 8:52
 */
@Data
public class ResultData {

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回数据
     */
    private Object data;

    /**
     * 返回静态成功方法
     * @return
     */
    public static ResultData success() {
        ResultData resultData = new ResultData();
        resultData.setCode(ResultCode.SUCCESS.getCode());
        resultData.setMessage(ResultCode.SUCCESS.getMessage());
        return resultData;
    }

    /**
     * 返回静态失败方法
     * @return
     */
    public static ResultData fail() {
        ResultData resultData = new ResultData();
        resultData.setCode(ResultCode.FAIL.getCode());
        resultData.setMessage(ResultCode.FAIL.getMessage());
        return resultData;
    }

    /**
     * 设置返回码
     * @param code
     * @return
     */
    public ResultData code(Integer code) {
        this.setCode(code);
        return this;
    }

    /**
     * 设置返回信息
     * @param message
     * @return
     */
    public ResultData message(String message) {
        this.setMessage(message);
        return this;
    }

    /**
     * 设置返回数据
     * @param obj
     * @return
     */
    public ResultData data(Object obj) {
        this.setData(obj);
        return this;
    }
}
